package 图.无向图;

import 图.深度优先遍历;
import 抽象数据类型.Graph;

/**
 * @description:
 * @author: ywk
 * @date: 2021-07-27
 */
public class 寻找路径 {
    public static void main(String[] args) {
        int[] arr1 = {0, 1, 2, 0, 3, 4, 5, 6, 7, 9, 10, 11, 12};
        int[] arr2 = {6, 0, 0, 5, 5, 3, 4, 4, 8, 11, 9, 12, 9};
        Graph G = new Graph(arr1.length);
        G.addGraph(arr1, arr2);
        深度优先遍历.DepthFirstPaths paths = new 深度优先遍历.DepthFirstPaths(G, 0);
        for (int v = 0; v < G.V(); v++) {
            System.out.print(0 + " to " + v + ":");
            if (paths.hasPathTo(v)) {
                for (Integer x : paths.pathTo(v)) {
                    if (x == 0) {
                        System.out.print(x);
                    } else {
                        System.out.print(x + "-");
                    }
                }

            }
            System.out.println();
        }
    }



}
